Generated by Cython 3.0.2

Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.

Raw output: simulate_photoswitching_time_tracks.c

+001: # cython: infer_types=True, wraparound=False, nonecheck=False, boundscheck=False, cdivision=True, language_level=3, profile=False, autogen_pxd=True
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_kp_u_simple_state_transition_model_li, __pyx_kp_u_Simple_photoswitching_state_tra) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_5) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 002: 
 003: from ..utils.random cimport _random
 004: 
+005: import numpy as np
  __pyx_t_7 = __Pyx_ImportDottedModule(__pyx_n_s_numpy, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_7) < 0) __PYX_ERR(0, 5, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 006: cimport numpy as np
 007: 
 008: from cython.parallel import prange
+009: from tqdm import tqdm
  __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_s_tqdm);
  __Pyx_GIVEREF(__pyx_n_s_tqdm);
  if (__Pyx_PyList_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_tqdm)) __PYX_ERR(0, 9, __pyx_L1_error);
  __pyx_t_4 = __Pyx_Import(__pyx_n_s_tqdm, __pyx_t_7, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_tqdm); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_tqdm, __pyx_t_7) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
 010: 
+011: def simple_state_transition_model(int n_particles, int n_ticks, double p_on, double p_transient_off, double p_permanent_off, int initial_state = 1) -> np.ndarray:
/* Python wrapper */
static PyArrayObject *__pyx_pw_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks_1simple_state_transition_model(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
PyDoc_STRVAR(__pyx_doc_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks_simple_state_transition_model, "\n    Simple photoswitching state transition model\n    :param n_particles: number of particles\n    :param n_ticks: number of time ticks\n    :param p_on: probability of switching on\n    :param p_transient_off: probability of switching off transiently\n    :param p_permanent_off: probability of switching off permanently\n    :param initial_state: initial state of the photoswitch\n    :return: array of states with shape (n_particles, n_ticks)\n\n    States:\n        -1: bleached\n        0: off\n        1: on\n    Transitions:\n        -1 -> -1\n        0 -> 0\n        1 -> 1\n        0 -> 1 with probability p_on\n        1 -> 0 with probability p_transient_off\n        1 -> -1 with probability p_permanent_off\n\n    Example:\n        >>> n_ticks = 1000\n        >>> n_particles = 100\n        >>> p_on = 0.1\n        >>> p_transient_off = 0.8\n        >>> p_permanent_off = 0.1\n        >>> initial_state = 0\n        >>> states = simple_state_transition_model(n_ticks, n_particles, p_on, p_transient_off, p_permanent_off, initial_state)\n    ");
static PyMethodDef __pyx_mdef_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks_1simple_state_transition_model = {"simple_state_transition_model", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks_1simple_state_transition_model, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks_simple_state_transition_model};
static PyArrayObject *__pyx_pw_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks_1simple_state_transition_model(PyObject *__pyx_self, 
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
  int __pyx_v_n_particles;
  int __pyx_v_n_ticks;
  double __pyx_v_p_on;
  double __pyx_v_p_transient_off;
  double __pyx_v_p_permanent_off;
  int __pyx_v_initial_state;
  #if !CYTHON_METH_FASTCALL
  CYTHON_UNUSED Py_ssize_t __pyx_nargs;
  #endif
  CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
  PyArrayObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("simple_state_transition_model (wrapper)", 0);
  #if !CYTHON_METH_FASTCALL
  #if CYTHON_ASSUME_SAFE_MACROS
  __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
  #else
  __pyx_nargs = PyTuple_Size(__pyx_args);
  if (unlikely((__pyx_nargs < 0))) __PYX_ERR(0, 11, __pyx_L3_error)
  #endif
  #endif
  __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
  {
    PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n_particles,&__pyx_n_s_n_ticks,&__pyx_n_s_p_on,&__pyx_n_s_p_transient_off,&__pyx_n_s_p_permanent_off,&__pyx_n_s_initial_state,0};
  PyObject* values[6] = {0,0,0,0,0,0};
    if (__pyx_kwds) {
      Py_ssize_t kw_args;
      switch (__pyx_nargs) {
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
      switch (__pyx_nargs) {
        case  0:
        if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_n_particles)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_n_ticks)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[1]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("simple_state_transition_model", 0, 5, 6, 1); __PYX_ERR(0, 11, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_p_on)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[2]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("simple_state_transition_model", 0, 5, 6, 2); __PYX_ERR(0, 11, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_p_transient_off)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[3]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("simple_state_transition_model", 0, 5, 6, 3); __PYX_ERR(0, 11, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (likely((values[4] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_p_permanent_off)) != 0)) {
          (void)__Pyx_Arg_NewRef_FASTCALL(values[4]);
          kw_args--;
        }
        else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
        else {
          __Pyx_RaiseArgtupleInvalid("simple_state_transition_model", 0, 5, 6, 4); __PYX_ERR(0, 11, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_initial_state);
          if (value) { values[5] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
          else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        const Py_ssize_t kwd_pos_args = __pyx_nargs;
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "simple_state_transition_model") < 0)) __PYX_ERR(0, 11, __pyx_L3_error)
      }
    } else {
      switch (__pyx_nargs) {
        case  6: values[5] = __Pyx_Arg_FASTCALL(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = __Pyx_Arg_FASTCALL(__pyx_args, 4);
        values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3);
        values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2);
        values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
        values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_n_particles = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_n_particles == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
    __pyx_v_n_ticks = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_n_ticks == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
    __pyx_v_p_on = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_p_on == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
    __pyx_v_p_transient_off = __pyx_PyFloat_AsDouble(values[3]); if (unlikely((__pyx_v_p_transient_off == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
    __pyx_v_p_permanent_off = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_p_permanent_off == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
    if (values[5]) {
      __pyx_v_initial_state = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_initial_state == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
    } else {
      __pyx_v_initial_state = ((int)((int)1));
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("simple_state_transition_model", 0, 5, 6, __pyx_nargs); __PYX_ERR(0, 11, __pyx_L3_error)
  goto __pyx_L3_error;
  __pyx_L3_error:;
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_AddTraceback("nanopyx.core.generate.simulate_photoswitching_time_tracks.simple_state_transition_model", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks_simple_state_transition_model(__pyx_self, __pyx_v_n_particles, __pyx_v_n_ticks, __pyx_v_p_on, __pyx_v_p_transient_off, __pyx_v_p_permanent_off, __pyx_v_initial_state);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  {
    Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
      __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
    }
  }
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyArrayObject *__pyx_pf_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks_simple_state_transition_model(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_n_particles, int __pyx_v_n_ticks, double __pyx_v_p_on, double __pyx_v_p_transient_off, double __pyx_v_p_permanent_off, int __pyx_v_initial_state) {
  __Pyx_memviewslice __pyx_v_states = { 0, 0, { 0 }, { 0 }, { 0 } };
  int __pyx_v_i;
  int __pyx_v_b;
  CYTHON_UNUSED int __pyx_v_b_stop;
  int __pyx_v__initial_state;
  PyObject *__pyx_v_progress_bar = NULL;
  PyArrayObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("simple_state_transition_model", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XCLEAR_MEMVIEW(&__pyx_t_21, 1);
  __Pyx_AddTraceback("nanopyx.core.generate.simulate_photoswitching_time_tracks.simple_state_transition_model", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XCLEAR_MEMVIEW(&__pyx_v_states, 1);
  __Pyx_XDECREF(__pyx_v_progress_bar);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__23 = PyTuple_Pack(12, __pyx_n_s_n_particles, __pyx_n_s_n_ticks, __pyx_n_s_p_on, __pyx_n_s_p_transient_off, __pyx_n_s_p_permanent_off, __pyx_n_s_initial_state, __pyx_n_s_states, __pyx_n_s_i, __pyx_n_s_b, __pyx_n_s_b_stop, __pyx_n_s_initial_state_2, __pyx_n_s_progress_bar); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);
/* … */
  __pyx_t_4 = __Pyx_PyInt_From_int(((int)1)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_4);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4)) __PYX_ERR(0, 11, __pyx_L1_error);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_return, __pyx_kp_s_np_ndarray) < 0) __PYX_ERR(0, 11, __pyx_L1_error)
  __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks_1simple_state_transition_model, 0, __pyx_n_s_simple_state_transition_model, NULL, __pyx_n_s_nanopyx_core_generate_simulate_p, __pyx_d, ((PyObject *)__pyx_codeobj__24)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_5, __pyx_t_7);
  __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_5, __pyx_t_4);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_simple_state_transition_model, __pyx_t_5) < 0) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 012:     """
 013:     Simple photoswitching state transition model
 014:     :param n_particles: number of particles
 015:     :param n_ticks: number of time ticks
 016:     :param p_on: probability of switching on
 017:     :param p_transient_off: probability of switching off transiently
 018:     :param p_permanent_off: probability of switching off permanently
 019:     :param initial_state: initial state of the photoswitch
 020:     :return: array of states with shape (n_particles, n_ticks)
 021: 
 022:     States:
 023:         -1: bleached
 024:         0: off
 025:         1: on
 026:     Transitions:
 027:         -1 -> -1
 028:         0 -> 0
 029:         1 -> 1
 030:         0 -> 1 with probability p_on
 031:         1 -> 0 with probability p_transient_off
 032:         1 -> -1 with probability p_permanent_off
 033: 
 034:     Example:
 035:         >>> n_ticks = 1000
 036:         >>> n_particles = 100
 037:         >>> p_on = 0.1
 038:         >>> p_transient_off = 0.8
 039:         >>> p_permanent_off = 0.1
 040:         >>> initial_state = 0
 041:         >>> states = simple_state_transition_model(n_ticks, n_particles, p_on, p_transient_off, p_permanent_off, initial_state)
 042:     """
+043:     cdef int[:,:] states = np.zeros((n_particles, n_ticks), dtype=np.int32)
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_n_particles); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_ticks); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error);
  __Pyx_GIVEREF(__pyx_t_3);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error);
  __pyx_t_1 = 0;
  __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4)) __PYX_ERR(0, 43, __pyx_L1_error);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsds_int(__pyx_t_5, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_states = __pyx_t_6;
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;
 044:     cdef int i, b, b_stop
+045:     cdef int _initial_state = initial_state
  __pyx_v__initial_state = __pyx_v_initial_state;
 046: 
 047:     # break it down to 100 tracks at a time
+048:     with tqdm(total=n_particles, desc="Tracing", unit="particles") as progress_bar:
  /*with:*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_tqdm); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 48, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 48, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_n_particles); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 48, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_total, __pyx_t_3) < 0) __PYX_ERR(0, 48, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_desc, __pyx_n_u_Tracing) < 0) __PYX_ERR(0, 48, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_unit, __pyx_n_u_particles) < 0) __PYX_ERR(0, 48, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 48, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_3, __pyx_n_s_exit); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 48, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = __Pyx_PyObject_LookupSpecial(__pyx_t_3, __pyx_n_s_enter); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 48, __pyx_L3_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = NULL;
    __pyx_t_8 = 0;
    #if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_8 = 1;
      }
    }
    #endif
    {
      PyObject *__pyx_callargs[1] = {__pyx_t_2, };
      __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_8, 0+__pyx_t_8);
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 48, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __pyx_t_5 = __pyx_t_4;
    __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    /*try:*/ {
      {
        /*try:*/ {
          __pyx_v_progress_bar = __pyx_t_5;
          __pyx_t_5 = 0;
/* … */
        }
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L12_try_end;
        __pyx_L7_error:;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __PYX_XCLEAR_MEMVIEW(&__pyx_t_21, 1);
        __pyx_t_21.memview = NULL; __pyx_t_21.data = NULL;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __PYX_XCLEAR_MEMVIEW(&__pyx_t_6, 1);
        __pyx_t_6.memview = NULL; __pyx_t_6.data = NULL;
        /*except:*/ {
          __Pyx_AddTraceback("nanopyx.core.generate.simulate_photoswitching_time_tracks.simple_state_transition_model", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_3, &__pyx_t_4) < 0) __PYX_ERR(0, 48, __pyx_L9_except_error)
          __Pyx_XGOTREF(__pyx_t_5);
          __Pyx_XGOTREF(__pyx_t_3);
          __Pyx_XGOTREF(__pyx_t_4);
          __pyx_t_2 = PyTuple_Pack(3, __pyx_t_5, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 48, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_22 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_2, NULL);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 48, __pyx_L9_except_error)
          __Pyx_GOTREF(__pyx_t_22);
          __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_22);
          __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
          if (__pyx_t_17 < 0) __PYX_ERR(0, 48, __pyx_L9_except_error)
          __pyx_t_23 = (!__pyx_t_17);
          if (unlikely(__pyx_t_23)) {
            __Pyx_GIVEREF(__pyx_t_5);
            __Pyx_GIVEREF(__pyx_t_3);
            __Pyx_XGIVEREF(__pyx_t_4);
            __Pyx_ErrRestoreWithState(__pyx_t_5, __pyx_t_3, __pyx_t_4);
            __pyx_t_5 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; 
            __PYX_ERR(0, 48, __pyx_L9_except_error)
          }
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          goto __pyx_L8_exception_handled;
        }
        __pyx_L9_except_error:;
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        goto __pyx_L1_error;
        __pyx_L8_exception_handled:;
        __Pyx_XGIVEREF(__pyx_t_9);
        __Pyx_XGIVEREF(__pyx_t_10);
        __Pyx_XGIVEREF(__pyx_t_11);
        __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        __pyx_L12_try_end:;
      }
    }
    /*finally:*/ {
      /*normal exit:*/{
        if (__pyx_t_7) {
          __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__11, NULL);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 48, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
        goto __pyx_L6;
      }
      __pyx_L6:;
    }
    goto __pyx_L29;
    __pyx_L3_error:;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    goto __pyx_L1_error;
    __pyx_L29:;
  }
/* … */
  __pyx_tuple__11 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);
+049:         for b in range(0, n_particles, 100):
          __pyx_t_8 = __pyx_v_n_particles;
          __pyx_t_12 = __pyx_t_8;
          for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=0x64) {
            __pyx_v_b = __pyx_t_13;
+050:             with nogil:
            {
                #ifdef WITH_THREAD
                PyThreadState *_save;
                _save = NULL;
                Py_UNBLOCK_THREADS
                __Pyx_FastGIL_Remember();
                #endif
                /*try:*/ {
/* … */
                /*finally:*/ {
                  /*normal exit:*/{
                    #ifdef WITH_THREAD
                    __Pyx_FastGIL_Forget();
                    Py_BLOCK_THREADS
                    #endif
                    goto __pyx_L19;
                  }
                  __pyx_L18_error: {
                    #ifdef WITH_THREAD
                    __Pyx_FastGIL_Forget();
                    Py_BLOCK_THREADS
                    #endif
                    goto __pyx_L7_error;
                  }
                  __pyx_L19:;
                }
            }
+051:                 b_stop = min(b + 100, n_particles)
                  __pyx_t_14 = __pyx_v_n_particles;
                  __pyx_t_15 = (__pyx_v_b + 0x64);
                  __pyx_t_17 = (__pyx_t_14 < __pyx_t_15);
                  if (__pyx_t_17) {
                    __pyx_t_16 = __pyx_t_14;
                  } else {
                    __pyx_t_16 = __pyx_t_15;
                  }
                  __pyx_v_b_stop = __pyx_t_16;
+052:                 for i in prange(b, b_stop):
                  __pyx_t_14 = __pyx_v_b;
                  __pyx_t_18 = __pyx_v_b_stop;
                  {
                      #if ((defined(__APPLE__) || defined(__OSX__)) && (defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))))
                          #undef likely
                          #undef unlikely
                          #define likely(x)   (x)
                          #define unlikely(x) (x)
                      #endif
                      __pyx_t_20 = (__pyx_t_18 - __pyx_t_14 + 1 - 1/abs(1)) / 1;
                      if (__pyx_t_20 > 0)
                      {
                          #ifdef _OPENMP
                          #pragma omp parallel
                          #endif /* _OPENMP */
                          {
                              #ifdef _OPENMP
                              #pragma omp for firstprivate(__pyx_v_i) lastprivate(__pyx_v_i)
                              #endif /* _OPENMP */
                              for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_20; __pyx_t_19++){
                                  {
                                      __pyx_v_i = (int)(__pyx_t_14 + 1 * __pyx_t_19);
+053:                     _simple_state_transition_model(states[i,:], p_on, p_transient_off, p_permanent_off, _initial_state)
                                      __pyx_t_21.data = __pyx_v_states.data;
                                      __pyx_t_21.memview = __pyx_v_states.memview;
                                      __PYX_INC_MEMVIEW(&__pyx_t_21, 0);
                                      {
    Py_ssize_t __pyx_tmp_idx = __pyx_v_i;
    Py_ssize_t __pyx_tmp_stride = __pyx_v_states.strides[0];
        __pyx_t_21.data += __pyx_tmp_idx * __pyx_tmp_stride;
}

__pyx_t_21.shape[0] = __pyx_v_states.shape[1];
__pyx_t_21.strides[0] = __pyx_v_states.strides[1];
    __pyx_t_21.suboffsets[0] = -1;

__pyx_f_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks__simple_state_transition_model(__pyx_t_21, __pyx_v_p_on, __pyx_v_p_transient_off, __pyx_v_p_permanent_off, __pyx_v__initial_state); if (unlikely(__Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 53, __pyx_L22_error)
                                      __PYX_XCLEAR_MEMVIEW(&__pyx_t_21, 0);
                                      __pyx_t_21.memview = NULL; __pyx_t_21.data = NULL;
                                      goto __pyx_L25;
                                      __pyx_L22_error:;
                                      {
                                          #ifdef WITH_THREAD
                                          PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
                                          #endif
                                          #ifdef _OPENMP
                                          #pragma omp flush(__pyx_parallel_exc_type)
                                          #endif /* _OPENMP */
                                          if (!__pyx_parallel_exc_type) {
                                            __Pyx_ErrFetchWithState(&__pyx_parallel_exc_type, &__pyx_parallel_exc_value, &__pyx_parallel_exc_tb);
                                            __pyx_parallel_filename = __pyx_filename; __pyx_parallel_lineno = __pyx_lineno; __pyx_parallel_clineno = __pyx_clineno;
                                            __Pyx_GOTREF(__pyx_parallel_exc_type);
                                          }
                                          #ifdef WITH_THREAD
                                          __Pyx_PyGILState_Release(__pyx_gilstate_save);
                                          #endif
                                      }
                                      __pyx_parallel_why = 4;
                                      goto __pyx_L24;
                                      __pyx_L24:;
                                      #ifdef _OPENMP
                                      #pragma omp critical(__pyx_parallel_lastprivates7)
                                      #endif /* _OPENMP */
                                      {
                                          __pyx_parallel_temp0 = __pyx_v_i;
                                      }
                                      __pyx_L25:;
                                      #ifdef _OPENMP
                                      #pragma omp flush(__pyx_parallel_why)
                                      #endif /* _OPENMP */
                                  }
                              }
                              #ifdef _OPENMP
                              Py_END_ALLOW_THREADS
                              #else
{
#ifdef WITH_THREAD
                              PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
                              #endif
                              #endif /* _OPENMP */
                              /* Clean up any temporaries */
                              __PYX_XCLEAR_MEMVIEW(&__pyx_t_21, 0);
                              __pyx_t_21.memview = NULL; __pyx_t_21.data = NULL;
                              #ifdef WITH_THREAD
                              __Pyx_PyGILState_Release(__pyx_gilstate_save);
                              #endif
                              #ifndef _OPENMP
}
#endif /* _OPENMP */
                          }
                      }
                      if (__pyx_parallel_exc_type) {
                        /* This may have been overridden by a continue, break or return in another thread. Prefer the error. */
                        __pyx_parallel_why = 4;
                      }
                      if (__pyx_parallel_why) {
                        __pyx_v_i = __pyx_parallel_temp0;
                        switch (__pyx_parallel_why) {
                              case 4:
                          {
                              #ifdef WITH_THREAD
                              PyGILState_STATE __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
                              #endif
                              __Pyx_GIVEREF(__pyx_parallel_exc_type);
                              __Pyx_ErrRestoreWithState(__pyx_parallel_exc_type, __pyx_parallel_exc_value, __pyx_parallel_exc_tb);
                              __pyx_filename = __pyx_parallel_filename; __pyx_lineno = __pyx_parallel_lineno; __pyx_clineno = __pyx_parallel_clineno;
                              #ifdef WITH_THREAD
                              __Pyx_PyGILState_Release(__pyx_gilstate_save);
                              #endif
                          }
                          goto __pyx_L18_error;
                        }
                      }
                  }
                  #if ((defined(__APPLE__) || defined(__OSX__)) && (defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))))
                      #undef likely
                      #undef unlikely
                      #define likely(x)   __builtin_expect(!!(x), 1)
                      #define unlikely(x) __builtin_expect(!!(x), 0)
                  #endif
                }
+054:             progress_bar.update(100)
            __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_progress_bar, __pyx_n_s_update); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 54, __pyx_L7_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_4 = NULL;
            __pyx_t_20 = 0;
            #if CYTHON_UNPACK_METHODS
            if (likely(PyMethod_Check(__pyx_t_3))) {
              __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
              if (likely(__pyx_t_4)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
                __Pyx_INCREF(__pyx_t_4);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_3, function);
                __pyx_t_20 = 1;
              }
            }
            #endif
            {
              PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_int_100};
              __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_20, 1+__pyx_t_20);
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 54, __pyx_L7_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            }
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          }
+055:     return np.asarray(states)
  __Pyx_XDECREF((PyObject *)__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_asarray); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __pyx_memoryview_fromslice(__pyx_v_states, 2, (PyObject *(*)(char *)) __pyx_memview_get_int, (int (*)(char *, PyObject *)) __pyx_memview_set_int, 0);; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  __pyx_t_8 = 0;
  #if CYTHON_UNPACK_METHODS
  if (unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
      __pyx_t_8 = 1;
    }
  }
  #endif
  {
    PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_3};
    __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 55, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 55, __pyx_L1_error)
  __pyx_r = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;
 056: 
 057: 
+058: cdef void _simple_state_transition_model(int[:] states, double p_on, double p_transient_off, double p_permanent_off, int initial_state) nogil:
static void __pyx_f_7nanopyx_4core_8generate_35simulate_photoswitching_time_tracks__simple_state_transition_model(__Pyx_memviewslice __pyx_v_states, double __pyx_v_p_on, double __pyx_v_p_transient_off, double __pyx_v_p_permanent_off, int __pyx_v_initial_state) {
  int __pyx_v_n_ticks;
  int __pyx_v_current_state;
  int __pyx_v_i;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_simple_state_transition_model", 1);
/* … */
  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  #ifdef WITH_THREAD
  __pyx_gilstate_save = __Pyx_PyGILState_Ensure();
  #endif
  __Pyx_AddTraceback("nanopyx.core.generate.simulate_photoswitching_time_tracks._simple_state_transition_model", __pyx_clineno, __pyx_lineno, __pyx_filename);
  #ifdef WITH_THREAD
  __Pyx_PyGILState_Release(__pyx_gilstate_save);
  #endif
  __pyx_L0:;
  __Pyx_RefNannyFinishContextNogil()
}
 059:     """
 060:     Simple photoswitching state transition model
 061:     :param states: array of states
 062:     :param p_on: probability of switching on
 063:     :param p_transient_off: probability of switching off transiently
 064:     :param p_permanent_off: probability of switching off permanently
 065:     :param initial_state: initial state of the photoswitch
 066: 
 067:     States:
 068:         -1: bleached
 069:         0: off
 070:         1: on
 071:     Transitions:
 072:         -1 -> -1
 073:         0 -> 0
 074:         1 -> 1
 075:         0 -> 1 with probability p_on
 076:         1 -> 0 with probability p_transient_off
 077:         1 -> -1 with probability p_permanent_off
 078:     """
 079: 
+080:     cdef int n_ticks = states.shape[0]
  __pyx_v_n_ticks = (__pyx_v_states.shape[0]);
+081:     cdef int current_state = initial_state
  __pyx_v_current_state = __pyx_v_initial_state;
 082: 
+083:     for i in range(n_ticks):
  __pyx_t_1 = __pyx_v_n_ticks;
  __pyx_t_2 = __pyx_t_1;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_i = __pyx_t_3;
+084:         if current_state == -1:
    switch (__pyx_v_current_state) {
      case -1L:
/* … */
      break;
      case 0:
+085:             states[i] = -1
      __pyx_t_4 = __pyx_v_i;
      *((int *) ( /* dim=0 */ (__pyx_v_states.data + __pyx_t_4 * __pyx_v_states.strides[0]) )) = -1;
+086:         elif current_state == 0:
      break;
      case 1:
+087:             if _random() < p_on:
      __pyx_t_5 = __pyx_f_7nanopyx_4core_5utils_6random__random(); if (unlikely(__Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 87, __pyx_L1_error)
      __pyx_t_6 = (__pyx_t_5 < __pyx_v_p_on);
      if (__pyx_t_6) {
/* … */
        goto __pyx_L5;
      }
+088:                 current_state = 1
        __pyx_v_current_state = 1;
+089:                 states[i] = 1
        __pyx_t_4 = __pyx_v_i;
        *((int *) ( /* dim=0 */ (__pyx_v_states.data + __pyx_t_4 * __pyx_v_states.strides[0]) )) = 1;
 090:             else:
+091:                 states[i] = 0
      /*else*/ {
        __pyx_t_4 = __pyx_v_i;
        *((int *) ( /* dim=0 */ (__pyx_v_states.data + __pyx_t_4 * __pyx_v_states.strides[0]) )) = 0;
      }
      __pyx_L5:;
+092:         elif current_state == 1:
      break;
      default: break;
    }
  }
+093:             if _random() < p_permanent_off:
      __pyx_t_5 = __pyx_f_7nanopyx_4core_5utils_6random__random(); if (unlikely(__Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 93, __pyx_L1_error)
      __pyx_t_6 = (__pyx_t_5 < __pyx_v_p_permanent_off);
      if (__pyx_t_6) {
/* … */
        goto __pyx_L6;
      }
+094:                 current_state = -1
        __pyx_v_current_state = -1;
+095:                 states[i] = -1
        __pyx_t_4 = __pyx_v_i;
        *((int *) ( /* dim=0 */ (__pyx_v_states.data + __pyx_t_4 * __pyx_v_states.strides[0]) )) = -1;
+096:             elif _random() < p_transient_off:
      __pyx_t_5 = __pyx_f_7nanopyx_4core_5utils_6random__random(); if (unlikely(__Pyx_ErrOccurredWithGIL())) __PYX_ERR(0, 96, __pyx_L1_error)
      __pyx_t_6 = (__pyx_t_5 < __pyx_v_p_transient_off);
      if (__pyx_t_6) {
/* … */
        goto __pyx_L6;
      }
+097:                 current_state = 0
        __pyx_v_current_state = 0;
+098:                 states[i] = 0
        __pyx_t_4 = __pyx_v_i;
        *((int *) ( /* dim=0 */ (__pyx_v_states.data + __pyx_t_4 * __pyx_v_states.strides[0]) )) = 0;
 099:             else:
+100:                 states[i] = 1
      /*else*/ {
        __pyx_t_4 = __pyx_v_i;
        *((int *) ( /* dim=0 */ (__pyx_v_states.data + __pyx_t_4 * __pyx_v_states.strides[0]) )) = 1;
      }
      __pyx_L6:;